﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBA.Common;
using DBA.Model;
using DBA.Data;
using DBA.Data.ADO;

namespace DBA.Web.ProjectManage
{
    public partial class Workload : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (!String.IsNullOrEmpty(Request.Params["id"]))
                {
                    hidID.Value = RequestHelper.QueryString("id");
                    ModifyRoleInit();
                }
            }
        }

        DataAccessLibrary dal = CommonQuery.DataAccessLibrary;

        protected void lnkSave_Click(object sender, EventArgs e)
        {

            WorkSharing model = ConvertHelper.ControlToModel<WorkSharing>(pan_tab.Controls);
            model.Sp_ID = int.Parse(Request.Params["EmpID"]);
            if (!VerificationHelper.IsNullOrEmpty<string>(hidID.Value))
            {
                model.Ws_ID = ConvertHelper.ToInt32(hidID.Value);
            }
            if (hidID.Value.Equals(string.Empty))//添加学生信息
            {

                hdResult.Value = dal.ModifyData.Insert<WorkSharing>(model).ToString();
            }
            else //修改学生信息
            {
                if (dal.ModifyData.Update<WorkSharing>(model) == "0")
                {
                    hdResult.Value = "0";
                }
                else
                {
                    hdResult.Value = "1";
                }
            }
        }

        /// <summary>
        /// 修改用户页面初始化
        /// </summary>
        private void ModifyRoleInit()
        {
            string id = hidID.Value;
            if (!VerificationHelper.IsNullOrEmpty<string>(id))
            {
                WorkSharing model = dal.ModifyData.GetEntity<WorkSharing>(id);
                if (!VerificationHelper.IsNullOrEmpty<WorkSharing>(model)) //如果学生对象不为空，那么对控件赋值
                {
                    ConvertHelper.ModelToControl<WorkSharing>(model, pan_tab.Controls);
                }
            }
        }
    }
}